package services.impl;

import dao.BillMapper;
import domain.Bill;
import org.springframework.stereotype.Service;
import services.BillService;
import utils.PageBean;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BillServiceImpl implements BillService {
    @Resource
    private BillMapper billMapper;

    @Override
    public List<Bill> queryBillByPage(String productName, int pid, int isPayment, PageBean pageBean) {
        List<Bill> billList = billMapper.queryBillByPage(productName,pid,isPayment,pageBean);
        return billList;
    }

    @Override
    public boolean addBill(Bill bill) {
        boolean flag = false;
        int row = billMapper.addBill(bill);
        if(row>0){
            //添加成功
            flag = true;
        }
        return flag;
    }

    @Override
    public Bill queryBillById(int bid) {
        return billMapper.queryBillById(bid);
    }

    @Override
    public boolean modifyBill(Bill bill) {
        Boolean flag = false;
        int row = billMapper.modifyBill(bill);
        if(row>0){
            //修改成功
            flag = true;
        }
        return flag;
    }

    /**
     * 0:失败
     * 1:订单不存在
     * 2:删除成功
     * @param bid
     * @return
     */
    @Override
    public int deleteBill(int bid) {
        int flag = 0; //删除失败
        Bill bill = null;
        //判断订单是否存在
        bill = billMapper.queryBillById(bid);
        if(bill == null){
            //订单不存在
            flag = 1;
        }else {
            int row = billMapper.deleteBill(bid);
            if(row>0){
                //删除成功
                flag = 2;
            }
        }
        return flag;
    }

    @Override
    public int totalPage() {
        return billMapper.totalCount();
    }
}
